package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.redis.MessageConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *    移动端 套餐列表查询
 */
@RestController
@RequestMapping("setmeal")
@Api(tags = "移动端-套餐管理")
public class SetmealController {

    @Reference(timeout = 1500,mock = "com.itheima.health.service.SetmealServiceMock")
    private SetmealService setmealService;

    @GetMapping("findAllSetmeal")
    @ApiOperation(value = "查询所有套餐列表",notes = "移动端套餐列表查询")
    public Result findAllSetmeal(){
        return  new Result(setmealService.findAllSetmeal());
    }

    @GetMapping("findSetMealDetail/{id}")
    @ApiOperation(value = "套餐详情",notes = "移动端套餐列表查询")
    public Result findSetMealDetail(@PathVariable("id") int id){
        return  new Result(setmealService.findSetMealDetail(id));
    }

    @RequestMapping("findSetmealById/{id}")
    public  Result  findSetmealById(@PathVariable("id")  Integer id){
        try {
            Setmeal setmeal = setmealService.findSetmealById(id);
            return  new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
